import { useIntersectionObserver } from "@vueuse/core"
import { ref } from "vue"

export function useLazyData(callback: () => void) {
  const target = ref(null)
  const { stop } = useIntersectionObserver(target, ([{isIntersecting}]) => {
    if(isIntersecting) {
        // 进入可视区要做的事情
        callback()
        // 停止加载
        stop()
      }
 }, {
  // 阈值
  threshold: 0
 })
 return target
}